<template>
  <div >
    <BlogHeader :active-index="'3'"></BlogHeader>
    <el-form ref="form" :model="form" label-width="80px" class="main">
      <el-form-item label="昵称">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.psw"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click.prevent="onsubmit">管理员登录</el-button>
      </el-form-item>
    </el-form>
  </div>



</template>

<script>
import BlogHeader from "../components/BlogHeader";
import {postManagerLogin} from "../api/api";
import QuestionCreate from "./QuestionCreate";

export default {
  name: "ManagerLogin",
  components: {BlogHeader},

  data() {
    return({
      form: {
        name: '',
        psw: '',
      },
      rps: '',
    })
  },

  methods: {
    onsubmit() {
      postManagerLogin(this.form.name, this.form.psw)
        .then(response => {
          console.log(response)
          if(response.status === 200)
          {
            this.rps = response
            console.log(response)
            localStorage.setItem("mg-token", response.headers['y-access-token']);
            localStorage.setItem("manager", this.form.name);
            console.log(localStorage)
            alert('登录成功！')
            this.$router.push({name: 'QuestionCreate'});
          }

          // 路由跳转
          // 登录成功后来到编辑题目

        })
        .catch(error => {
          alert(error.message)
        });
      console.log(this.rps);
    },
  },


}
</script>

<style scoped>

.main {
  margin: 6em 20em 0 22em;
  height: 30em;
  width: 30em;}
</style>
